#include "myfront.h"
#include "myoled.h"

#define Chinese_Cnt 42
//汉字映射
u16 Chinese_GB2312_Table(char * codeStr) 
{
	switch(*codeStr)
	{
		case 0xB0:
			if(*(codeStr+1) == 0xB4)
				return 13;
			else if(*(codeStr+1) == 0xDC)
				return 30;
		break;
		case 0xB2:
				if(*(codeStr+1) == 0xE9) 
					return 10;
		break;
		case 0xB4:
				if(*(codeStr+1) == 0xAB) 
					return 24;
				else if(*(codeStr+1) == 0xAE) 
					return 40;
		break;
		case 0xB5:
				if(*(codeStr+1) == 0xC6) 
					return 12;
		break;
		case 0xB6:
				if(*(codeStr+1) == 0xC8) 
					return 1;
				else if(*(codeStr+1) == 0xCF) 
					return 27;
		break;
		case 0xB7:
				if(*(codeStr+1) == 0xAD) 
					return 15;
		break;
		case 0xB8:
				if(*(codeStr+1) == 0xA9) 
					return 17;
		break;
		case 0xB9:
				if(*(codeStr+1) == 0xF6) 
					return 16;
				else if(*(codeStr+1) == 0xA6)
					return 38;
		break;
		case 0xBA:
				if(*(codeStr+1) == 0xBD) 
					return 2;
		break;
		case 0xBC:
				if(*(codeStr+1) == 0xD3) 
					return 5;
		break;
		case 0xBD:
				if(*(codeStr+1) == 0xC7) 
					return 0;
				else if(*(codeStr+1) == 0xD3) 
					return 19;
				else if(*(codeStr+1) == 0xDA) 
					return 22;
		break;
		case 0xBF:
				if(*(codeStr+1) == 0xB4) 
					return 11;
				else if(*(codeStr+1) == 0xAA) 
					return 28;		
				else if(*(codeStr+1) == 0xDA) 
					return 41;
		break;
		case 0xC1:
				if(*(codeStr+1) == 0xAC) 
					return 25;
		break;
		case 0xC2:
				if(*(codeStr+1) == 0xDD)
					return 33;
		break;
		case 0xC4:
				if(*(codeStr+1) == 0xDC)
					return 39;
		break;
		case 0xC6:
				if(*(codeStr+1) == 0xAB) 
					return 4;
		break;
		case 0xCA:
				if(*(codeStr+1) == 0xA7) 
					return 29;
				else if(*(codeStr+1) == 0xD5) 
					return 20;
		break;
		case 0xCB:
				if(*(codeStr+1) == 0xD9) 
					return 6;
		break;
		case 0xCC:
				if(*(codeStr+1) == 0xAC) 
					return 9;
		break;
		case 0xCD:
				if(*(codeStr+1) == 0xB8) 
					return 23;
				else if(*(codeStr+1) == 0xD3)
					return 32;
				else if(*(codeStr+1) == 0xD8)
					return 36;
		break;
		case 0xCE:
				if(*(codeStr+1) == 0xDE)
					return 34;
		break;
		case 0xCF:
				if(*(codeStr+1) == 0xF2) 
					return 3;
				else if(*(codeStr+1) == 0xDF)
					return 35;
		break;
		case 0xD1:
				if(*(codeStr+1) == 0xF6) 
					return 18;
		break;
		case 0xD2:
			 if(*(codeStr+1) == 0xC7)
				 return 7;
		break;
		case 0xD5:
				if(*(codeStr+1) == 0xB9)
					return 37;
		break;
		case 0xD7:
				if(*(codeStr+1) == 0xB4) 
					return 8;
				else if(*(codeStr+1) == 0xD6) 
					return 21;	
		break;
	}
	return 31;
}

//汉字取模
char My_Chinese_Lib[Chinese_Cnt*32]=
{
0x20,0x10,0xE8,0x24,0x27,0x24,0x24,0xE4,
0x24,0x34,0x2C,0x20,0xE0,0x00,0x00,0x00,
0x80,0x60,0x1F,0x09,0x09,0x09,0x09,0x7F,
0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,/*"角",0*/
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,
0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,/*"度",1*/
0x80,0xFC,0x96,0xE5,0x84,0xFC,0x00,0x08,0xC8,0x49,0x4A,0xC8,0x08,0x08,0x00,0x00,0x80,0x7F,0x02,0x4C,0x80,0x7F,0x80,0x60,
0x1F,0x00,0x00,0x3F,0x40,0x40,0x78,0x00,/*"航",2*/
0x00,0xF8,0x08,0x08,0x0C,0xCA,0x49,0x48,0x48,0xC8,0x08,0x08,0x08,0xF8,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x1F,0x08,0x08,
0x08,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00,/*"向",3*/
0x80,0x60,0xF8,0x07,0x00,0xFC,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x3C,0x00,0x00,0x00,0x00,0xFF,0x40,0x3C,0x03,0xFF,0x09,
0x7F,0x09,0x7F,0x09,0x89,0xFF,0x00,0x00,/*"偏",4*/
0x10,0x10,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,0xF8,0x08,0x08,0x08,0xF8,0x00,0x00,0x80,0x40,0x30,0x0F,0x40,0x80,0x7F,0x00,
0x00,0x7F,0x20,0x20,0x20,0x7F,0x00,0x00,/*"加",5*/
0x40,0x40,0x42,0xCC,0x00,0x04,0xF4,0x94,0x94,0xFF,0x94,0x94,0xF4,0x04,0x00,0x00,0x00,0x40,0x20,0x1F,0x20,0x48,0x44,0x42,
0x41,0x5F,0x41,0x42,0x44,0x48,0x40,0x00,/*"速",6*/
0x00,0x80,0x60,0xF8,0x07,0x00,0x1C,0xE0,0x01,0x06,0x00,0xE0,0x1E,0x00,0x00,0x00,0x01,0x00,0x00,0xFF,0x00,0x80,0x40,0x20,
0x13,0x0C,0x13,0x20,0x40,0x80,0x80,0x00,/*"仪",7*/
0x00,0x08,0x30,0x00,0xFF,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x22,0x2C,0x20,0x00,0x04,0x04,0x02,0x01,0xFF,0x80,0x40,0x30,
0x0E,0x01,0x06,0x18,0x20,0x40,0x80,0x00,/*"状",8*/
0x00,0x04,0x84,0x84,0x44,0x24,0x54,0x8F,0x14,0x24,0x44,0x84,0x84,0x04,0x00,0x00,0x41,0x39,0x00,0x00,0x3C,0x40,0x40,0x42,
0x4C,0x40,0x40,0x70,0x04,0x09,0x31,0x00,/*"态",9*/
0x40,0x44,0x24,0xA4,0x94,0x8C,0x84,0xFF,0x84,0x8C,0x94,0xA4,0x24,0x44,0x40,0x00,0x40,0x40,0x40,0x5F,0x4A,0x4A,0x4A,0x4A,
0x4A,0x4A,0x4A,0x5F,0x40,0x40,0x40,0x00,/*"查",10*/
0x20,0x22,0x2A,0x2A,0xAA,0x6A,0x3A,0x2E,0x29,0x29,0x29,0x29,0x29,0x20,0x20,0x00,0x08,0x04,0x02,0x01,0xFF,0x55,0x55,0x55,
0x55,0x55,0x55,0xFF,0x00,0x00,0x00,0x00,/*"看",11*/
0x80,0x70,0x00,0xFF,0x20,0x10,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,0x80,0x60,0x18,0x07,0x08,0x30,0x00,0x00,
0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,/*"灯",12*/
0x10,0x10,0x10,0xFF,0x90,0x20,0x98,0x88,0x88,0xE9,0x8E,0x88,0x88,0xA8,0x98,0x00,0x02,0x42,0x81,0x7F,0x00,0x00,0x80,0x84,
0x4B,0x28,0x10,0x28,0x47,0x80,0x00,0x00,/*"按",13*/
0x40,0x30,0xEF,0x24,0x24,0x80,0xE4,0x9C,0x10,0x54,0x54,0xFF,0x54,0x7C,0x10,0x00,0x01,0x01,0x7F,0x21,0x51,0x26,0x18,0x27,
0x44,0x45,0x45,0x5F,0x45,0x45,0x44,0x00,/*"键",14*/
0x96,0x5A,0x32,0x7E,0x31,0x59,0x95,0x12,0x22,0xFE,0x00,0x12,0x22,0xFE,0x00,0x00,0x00,0xFF,0x49,0x7F,0x49,0xFF,0x00,0x44,
0x82,0x7F,0x04,0x42,0x81,0x7F,0x00,0x00,/*"翻",15*/
0x10,0x60,0x02,0x8C,0x00,0x24,0x94,0xCC,0xA5,0x96,0xC4,0x8C,0x14,0x24,0x00,0x00,0x04,0x04,0x7E,0x01,0x20,0x10,0x08,0xFC,
0x42,0x24,0x08,0x15,0x22,0x40,0x40,0x00,/*"滚",16*/
0x80,0x60,0xF8,0x07,0x00,0xFC,0x04,0xC4,0x34,0x85,0x86,0x84,0xF4,0x84,0x84,0x00,0x00,0x00,0xFF,0x40,0x30,0x0F,0x01,0xFF,
0x00,0x02,0x4C,0x80,0x7F,0x00,0x00,0x00,/*"俯",17*/
0x00,0x80,0x60,0xF8,0x07,0x00,0xFC,0x04,0x02,0x00,0xFC,0x04,0x04,0xFC,0x00,0x00,0x01,0x00,0x00,0xFF,0x00,0x00,0x1F,0x08,
0x04,0x00,0xFF,0x04,0x08,0x07,0x00,0x00,/*"仰",18*/
0x10,0x10,0x10,0xFF,0x10,0x50,0x44,0x54,0x65,0xC6,0x44,0x64,0x54,0x44,0x40,0x00,0x04,0x44,0x82,0x7F,0x01,0x82,0x82,0x4A,
0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00,/*"接",19*/
0x00,0xFC,0x00,0x00,0xFF,0x00,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,0x00,0x0F,0x04,0x02,0xFF,0x00,0x80,0x40,
0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,/*"收",20*/
0x10,0x0C,0x04,0x24,0x24,0x24,0x25,0x26,0xA4,0x64,0x24,0x04,0x04,0x14,0x0C,0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,/*"字",21*/
0x04,0x44,0x44,0x44,0x5F,0x44,0xC4,0x44,0x44,0x44,0x5F,0x44,0xC4,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,
0x00,0x08,0x10,0x08,0x07,0x00,0x00,0x00,/*"节",22*/
0x40,0x40,0x42,0xCC,0x00,0x48,0xAA,0x9A,0x8A,0xFE,0x89,0x99,0x29,0x48,0x40,0x00,0x00,0x40,0x20,0x1F,0x20,0x50,0x48,0x47,
0x40,0x40,0x42,0x4B,0x52,0x4E,0x40,0x00,/*"透",23*/
0x00,0x80,0x60,0xF8,0x07,0x40,0x48,0x48,0xE8,0x5F,0x48,0x48,0x48,0x40,0x40,0x00,0x01,0x00,0x00,0xFF,0x00,0x00,0x02,0x0B,
0x12,0x22,0xD2,0x0A,0x06,0x00,0x00,0x00,/*"传",24*/
0x40,0x40,0x42,0xCC,0x00,0x04,0x44,0x64,0x5C,0x47,0xF4,0x44,0x44,0x44,0x04,0x00,0x00,0x40,0x20,0x1F,0x20,0x44,0x44,0x44,
0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x00,/*"连",25*/
0x10,0x10,0x10,0xFF,0x10,0x50,0x44,0x54,0x65,0xC6,0x44,0x64,0x54,0x44,0x40,0x00,0x04,0x44,0x82,0x7F,0x01,0x82,0x82,0x4A,
0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00,/*"接",26*/
0x00,0xFC,0x20,0x24,0xA8,0xFF,0xA8,0x24,0x00,0xFC,0x44,0x44,0xC4,0x42,0x40,0x00,0x00,0x3F,0x22,0x21,0x20,0x2F,0x20,0xA3,
0x60,0x1F,0x00,0x00,0xFF,0x00,0x00,0x00,/*"断",27*/
0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,
0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*"开",28*/
0x00,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x81,0x81,0x41,0x21,0x11,0x0D,0x03,0x01,
0x03,0x0D,0x11,0x21,0x41,0x81,0x81,0x00,/*"失",29*/
0x00,0xFE,0x02,0xFA,0x02,0xFE,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x80,0x40,
0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,/*"败",30*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* 空 31*/
0x00,0xFE,0x02,0x22,0xDA,0x06,0x20,0xD8,0x08,0x09,0x0E,0x08,0x88,0x28,0x18,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,0x3F,
0x44,0x44,0x42,0x41,0x40,0x78,0x00,0x00,/*"陀",32*/
0x00,0xF8,0x08,0xFF,0x08,0xF8,0x00,0x3E,0xAA,0x6A,0x3E,0x2A,0xAA,0x3E,0x00,0x00,0x20,0x63,0x21,0x1F,0x11,0x39,0x48,0x29,
0x09,0x8D,0xFB,0x09,0x08,0x2C,0x58,0x00,/*"螺",33*/
0x00,0x40,0x42,0x42,0x42,0xC2,0x7E,0x42,0xC2,0x42,0x42,0x42,0x40,0x40,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,
0x3F,0x40,0x40,0x40,0x40,0x70,0x00,0x00,/*"无",34*/
0x20,0x30,0xAC,0x63,0x20,0x18,0x80,0x90,0x90,0xFF,0x90,0x49,0x4A,0x48,0x40,0x00,0x22,0x67,0x22,0x12,0x12,0x12,0x40,0x40,
0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00,/*"线",35*/
0x10,0x10,0x10,0xFF,0x10,0x90,0x04,0x04,0x84,0xE4,0x9C,0x84,0x84,0x84,0x04,0x00,0x04,0x44,0x82,0x7F,0x01,0x04,0x02,0x01,
0xFF,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,/*"拓",36*/
0x00,0x00,0xFE,0x12,0x92,0x92,0xF2,0x92,0x92,0x92,0xF2,0x92,0x92,0x1E,0x00,0x00,0x80,0x60,0x1F,0x04,0x04,0xFC,0x47,0x24,
0x0C,0x14,0x27,0x34,0x4C,0x44,0x44,0x00,/*"展",37*/
0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00,0x10,0x30,0x10,0x1F,0x08,0x88,0x48,0x30,
0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,/*"功",38*/
0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00,0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,
0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,/*"能",39*/
0x00,0x00,0x3C,0x24,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0x24,0x3C,0x00,0x00,0x00,0x00,0x1F,0x09,0x09,0x09,0x09,0x09,0xFF,
0x09,0x09,0x09,0x09,0x09,0x1F,0x00,0x00,/*"串",40*/
0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,0x00,0x00,0x00,0x7F,0x20,0x20,0x20,0x20,0x20,
0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00,/*"口",41*/
};

void OLED_Write_Chinese(u8 x, u8 y, u8 encodeNum)
{
	u8 i;
	OLED_Set_XY(x * 8, y);
    for (i=0; i<16; i++) 
    {
        OLED_WrDat(My_Chinese_Lib[encodeNum * 32 + i]); 
    }
    OLED_Set_XY(x * 8, y+1);
    for (i=0; i<16; i++) 
    {
        OLED_WrDat(My_Chinese_Lib[encodeNum * 32 + 16 + i]);  
    }	 	
}

void OLED_Write_Chinese_Str(u8 x, u8 y, char * tmpStr)
{
	u8 i,tmpNum,len = strlen(tmpStr);
	for(i = 0; i < len; i+=2)
	{
		tmpNum = Chinese_GB2312_Table(tmpStr);
		OLED_Write_Chinese(x+i, y, tmpNum); 
		tmpStr += 2;
	}
}

